<template>
    <div class="photoAlbumMain">
      <a class="colosePhotoAlbum" href="javascript:;" @click="$emit('listenToShowPhoto', false)">
        <i class="iconfont icon-cuowu"></i>
      </a>
      <!-- swiper -->
      <swiper ref="mySwiper" :options="swiperOption">
        <swiper-slide
        v-for="(item, index) in photos"
        :key="index">
          <img :src="item.url" alt="" ref="imgmaxheight">
          <p @click="$emit('listenToShowPhoto', false)">{{item.title}}</p>
        </swiper-slide>
        <div class="swiper-pagination"
        slot="pagination" @click="$emit('listenToShowPhoto', false)"
        ></div>
      </swiper>
    </div>
</template>

<script>
import { swiper, swiperSlide } from 'vue-awesome-swiper';

export default {
  name: 'PhotoAlbum', // 图片查看器
  data() {
    return {
      swiperOption: {
        autoplay: 5000,
        observer: true,
        observeParents: true,
        zoom: true,
        pagination: {
          el: '.swiper-pagination',
          type: 'fraction',
        },
      },
    };
  },
  props: {
    photos: Array,
    photoIndex: Number,
  },
  watch: {
    photoIndex: function change(val) {
      this.$refs.mySwiper.swiper.slideTo(val, 0, false);
    },
  },
  components: {
    swiper,
    swiperSlide,
  },
};
</script>

<style lang="scss" scoped>
  .photoAlbumMain {
    position: fixed;
    width: 100%;
    height: 100%;
    z-index: 9999999;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    top: 0;
    background: #000;

    .colosePhotoAlbum {
      position: absolute;
      width: 30px;
      height: 30px;
      z-index: 99999;
      top: 15px;
      right: 15px;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 100%;
      overflow: hidden;
      border: 1px solid #fff;

      i {
        font-size: .4rem;
      }
    }

    .photoalb {
      height: 80%;
      overflow-y: auto;
    }

    .swiper-container {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;

      .swiper-wrapper {
        .swiper-slide {
          width: 100% !important;
          min-width: 100%;
          max-height: 80%;
          overflow-y: auto;
          text-align: center;

          img {
            max-width: 100%;
          }

          p {
            color: #fff;
            padding: .2rem;
            word-wrap: break-word;
          }
        }
      }
    }
  }
</style>
